#include "chatroom.h"
#include"stdShared.h"
#include<cstring>
//构造函数
ChatRoom::ChatRoom(const stdTcpSocketPtr& clientInfo):m_clientSock(clientInfo)
{

}
ChatRoom::~ChatRoom() {}
//聊天室入口
void ChatRoom::ChatEnter()
{
    ChatMenu();
    int choice = 0;
    cin >> choice;
    choice += m_offset;
    switch (choice)
    {
    case ADDFRIEND:
        addFriend();
        break;
    case DELFRIEND:
        delFriend();
        break;
    case FRIENDCHAT:
        /* code */
        break;
    case FRIENDLIST:
        /* code */
        break;
    case NEWGROUP:
        /* code */
        break;
    case EXITGROUP:
        /* code */
        break;
    case JOINGROUP:
        /* code */
        break;
    case INVITEGROUP:
        /* code */
        break;
    case CHATGROUP:
        /* code */
        break;
    default:
        break;
    }
}
void ChatRoom::ChatMenu()
{
    cout<<"1、添加好友"<<endl;
    cout<<"2、删除好友"<<endl;
    cout<<"3、好友聊天"<<endl;
    cout<<"4、好友列表"<<endl;

    cout<<"5、创建群聊"<<endl;
    cout<<"6、退出群聊"<<endl;
    cout<<"7、加入群聊"<<endl;
    cout<<"8、邀请进群"<<endl;
    cout<<"9、群聊天"<<endl;

}

void ChatRoom::addFriend() 
{

    Msg msg;
    string addName;
    cout << "请输入联系人的用户名：" << endl;
    cin >> addName;
    msg.type = ADDFRIEND;
    strncpy(msg.toName, addName.c_str(), sizeof(msg.toName) - 1);
    // 发送信息给服务器
    m_clientSock->sendMessage(&msg,sizeof(msg));
    
}

void ChatRoom::delFriend() 
{
    Msg msg;
    string delName;
    cout << "请输入要删除联系人的用户名：" << endl;
    cin >> delName;
    msg.type = DELFRIEND;
    strncpy(msg.toName, delName.c_str(), sizeof(msg.toName) - 1);
    //发送信息给服务器
    m_clientSock->sendMessage(delName);
}
